/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_wtc_free.c                                      */
/*  NOTE      =                                                    */
/*  DATE      = 2016/02/24 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../src/module/tuxedowtc/config.h"
#include <tuxedowtc/wtc_core.h>
#include <tuxedowtc/wtc_header.h>
#include <tuxedowtc/wtc_comm.h>
#include <tuxedowtc/wtc_packet.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    void **pp_buffer;

    pp_buffer = NULL;

    wtc_free(pp_buffer);

    CU_ASSERT_PTR_NULL(pp_buffer);
}

static void __case2(void)
{
    void *p_buffer = NULL;

    wtc_free(&p_buffer);

    CU_ASSERT_PTR_NULL(p_buffer);
}

static void __case3(void)
{
    char *p_buffer = NULL;

    p_buffer = (char *) frmalloc(strlen("test") + 1);
    snprintf(p_buffer, strlen("test") + 1, "%s", "test");

    wtc_free((void **) &p_buffer);

    CU_ASSERT_PTR_NULL(p_buffer);
}

int add_suite_wtc_free(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" wtc_free()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
